package mo.tags.stack;

import java.util.Stack;

public class L2216 {

    public int minDeletion(int[] nums) {
        Stack<Integer> stack = new Stack<>();
        for (int num : nums) {
            if (stack.size() % 2 == 0) {
                stack.push(num);
            } else {
                if (stack.peek() == num) {
                    continue;
                }
                stack.push(num);
            }
        }
        if (stack.size() % 2 == 0) {
            return nums.length - stack.size();
        }
        return nums.length - stack.size() + 1;
    }

}
